package user;

import common.interfaces.AbstractHasID;

/**
 * Represents a user in the system
 * 
 * @author Gal Lalouche
 */
public class User extends AbstractHasID<String> {
	private static final String	REG_EXP	= "[A-Za-z]\\w*";
	private final String		login;
	private final String		name;
	
	/**
	 * Creates a new user
	 * 
	 * @param login The user's login
	 * @param name The user's name
	 */
	User(String login, String name) {
		if (login == null) {
			throw new IllegalArgumentException("login is null");
		}
		if (login.matches(REG_EXP) == false) {
			throw new IllegalArgumentException(
					"invalid login name; login must begin with a letter and cannot contain whitespaces");
		}
		this.login = login;
		if (name == null) {
			throw new IllegalArgumentException("name is null");
		}
		this.name = name;
	}
	
	/**
	 * @return the login
	 */
	public String getLogin() {
		return login;
	}
	
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	
	@Override
	public String toString() {
		return getClass().getCanonicalName() + "[name: " + name + ", login: " + login + "]";
	}
	
	@Override
	public String getId() {
		return getLogin();
	}
}
